<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
    	$sql="select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid =t2.id inner join category t3 on t1.cid =t3.id where t1.tips<>'0'";
        $tips = M()->query($sql);
    	$this->assign('tips',$tips);


      // 分页
      $count =  M('question')->where("tips='0'")->count();

       $Page = new \Think\Page($count,3);

       $show = $Page->show();

       $this->assign('page',$show);





        // 普通问题列表
        $sql = "select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tips='0' limit ".$Page->firstRow.",".$Page->listRows ;

    	$questions = M()->query($sql);
    	$this->assign('questions',$questions);

        $this->getTopView(); 
        $this->getTopAnswer();
         $this->getTopUser(); 
        $this->display();
    }

    // 全部问题列表
    public function All(){
     //  // 置顶和精华问题
     //    $sql="select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid =t2.id inner join category t3 on t1.cid =t3.id where t1.tips<>'0'";
     //    $import = M()->query($sql);
     //    $this->assign('import',$import);  

     // // 普通问题
     //  $sql = "select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.tips='0'" ;
     //  $common = M()->query($sql);
     //  $this->assign('common',$common);
    // 分页
      $count =  M('question')->count();

       $Page = new \Think\Page($count,5);

       $show = $Page->show();

       $this->assign('page',$show);

      $sql= "select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id limit " .$Page->firstRow.",".$Page->listRows;
        $questions =M()->query($sql);
        $this->assign('questions',$questions);
        $this->display();
    }
    
    // 未结帖
    public function unsolve(){

      $count = M('question')->where("status='未结贴'")->count();

       $Page = new \Think\Page($count,5);

       $show = $Page->show();

       $this->assign('page',$show);

        $sql= "select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.status='未结贴' limit ".$Page->firstRow.",".$Page->listRows;

        $unsolve =M()->query($sql);

        $this->assign('unsolve',$unsolve);
        $this->display();   




    }
    // 精贴
    public function Nice(){
        $count = M('question')->where("tips<>'0'")->count();

       $Page = new \Think\Page($count,3);

       $show = $Page->show();

       $this->assign('page',$show);
     $sql="select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid =t2.id inner join category t3 on t1.cid =t3.id where t1.tips<>'0'";
      $tips = M()->query($sql);
      $this->assign('tips',$tips);
      $this->display();
    }

    // 已采纳
    public function solve(){
      $count = M('question')->where("status='已采纳'")->count();

       $Page = new \Think\Page($count,5);

       $show = $Page->show();

       $this->assign('page',$show);
        $sql= "select t1.*,t2.nickname,t2.face,t3.cname from question t1 inner join user t2 on t1.uid=t2.id inner join category t3 on t1.cid=t3.id where t1.status='已采纳' limit ".$Page->firstRow.",".$Page->listRows;
        $solve =M()->query($sql);

        $this->assign('solve',$solve);
        $this->display();
    }

}